module("framework.luamono.MonoHelper",package.seeall)

---@class MonoHelper
local MonoHelper = {}

--给gameObject添加一个lua的component
--如果已经存在了某个类型的组件，则直接返回
--@ go GameObject
--@ clsDefine lua组件的类定义
function MonoHelper.addLuaComOnceToGo(go, clsDefine, ctorParam)
    if gohelper.isNil(go) then
        logError("MonoHelper.addLuaComOnceToGo, go can not be nil!")
        return nil
    end
    if not clsDefine then
        logError("MonoHelper.addLuaComOnceToGo, clsDefine can not be nil!")
        return nil
    end
    local container = Framework.LuaMonoTools.GetLuaComContainer(go, LuaMonoContainer)
    return container:addCompOnce(clsDefine, ctorParam)
end

--给gameObject添加一个不含update 和 physic的lua component,
--如果已经存在了某个类型的组件，则直接返回
--@ go GameObject
--@ clsDefine lua组件的类定义
function MonoHelper.addNoUpdateLuaComOnceToGo(go, clsDefine, ctorParam)
    if gohelper.isNil(go) then
        logError("MonoHelper.addNoUpdateLuaComOnceToGo, go can not be nil!")
        return nil
    end
    if not clsDefine then
        logError("MonoHelper.addNoUpdateLuaComOnceToGo, clsDefine can not be nil!")
        return nil
    end
    local container = Framework.LuaMonoTools.GetLuaComContainer(go, LuaNoUpdateMonoContainer)
    return container:addCompOnce(clsDefine, ctorParam)
end

--在gameObject的lua组件容器中查找一个lua的component
--@ go GameObject
--@ clsDefine lua组件的类定义
function MonoHelper.getLuaComFromGo(go, clsDefine)
    if gohelper.isNil(go) or not clsDefine then
        logError("MonoHelper.getLuaComFromGo, go and clsDefine can not be nil! ")
        return nil
    end
    local container = Framework.LuaMonoTools.FindLuaComContainer(go)
    if nil ~= container then
        return container:getComp(clsDefine)
    end
    --logError("MonoHelper.getLuaComFromGo, go = "..go.name.." does not have a lua com container!")
    return nil
end

--在gameObject的lua组件容器中查删除一个lua的component
--@ go GameObject
--@ clsDefine lua组件的类定义
function MonoHelper.removeLuaComFromGo(go, clsDefine)
    if gohelper.isNil(go) or not clsDefine then
        logError("MonoHelper.removeLuaComFromGo, go and clsDefine can not be nil! ")
        return nil
    end

    local container = Framework.LuaMonoTools.FindLuaComContainer(go)
    if nil ~= container then
        container:removeCompByDefine(clsDefine)
    end
end

--获取gameObject中的lua组件容器
--@ go 游戏物体
--@ lua组件容器对象
function MonoHelper.getLuaContainerInGo(go)
    if gohelper.isNil(go) then
        logError("MonoHelper.getLuaContainerInGo, go can not be nil!")
        return nil
    end
    return Framework.LuaMonoTools.FindLuaComContainer(go)
end

return MonoHelper
